package org.vy.dal.dao.lookup;

/**
 * @author Ravi Shankar
 *
 */

import java.util.List;

import org.vy.dal.QueryManager;

public class VyLookupQualificationDAO {

	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE qualification_code = m_QualificationCode";
	private static final String FIND_BY_PARAM = "SELECT * FROM <TABLE> WHERE 1 = 1 ";
	private static final String UPDATE = "UPDATE <TABLE> SET qualification_code = m_QualificationCode,qualification_name=m_QualificationName, is_active=m_IsActive, last_updated_by=m_LastUpdtBy, last_updated_on=m_LastUpdatedOn WHERE qualification_code = m_QualificationCode";
	private static final String INSERT = "INSERT INTO <TABLE> (qualification_code,qualification_name,is_active,last_updated_by,last_updated_on) VALUES (m_QualificationCode,m_QualificationName,m_IsActive,m_LastUpdtBy,m_LastUpdtOn)";
	private static final String DELETE = "UPDATE <TABLE> SET IS_ACTIVE = FALSE WHERE qualification_code = m_QualificationCode";

	public static VyLookupQualificationDO findByPK(String key) throws Exception {
		VyLookupQualificationDO dto = new VyLookupQualificationDO();
		dto.setQualificationCode(key);
		dto = (VyLookupQualificationDO) QueryManager.executeQuery(dto,
				FIND_BY_PK);
		return dto;
	}

	@SuppressWarnings("unchecked")
	public static List<VyLookupQualificationDO> findByParam(
			VyLookupQualificationDO dto) throws Exception {
		StringBuilder sb = new StringBuilder(FIND_BY_PARAM);
		if (dto.getQualificationCode() != null) {
			sb.append(" AND qualification_code LIKE '%"
					+ dto.getQualificationCode() + "%' ");
		}
		if (dto.getQualificationName() != null) {
			sb.append(" AND qualification_name LIKE '%"
					+ dto.getQualificationName() + "%' ");
		}
		if (dto.getIsActive() != null) {
			sb.append(" AND is_active LIKE '%" + dto.getIsActive() + "%' ");
		}
		if (dto.getLastUpdtBy() != null) {
			sb.append(" AND last_updated_by LIKE '%" + dto.getLastUpdtBy()
					+ "%' ");
		}
		if (dto.getLastUpdtOn() != null) {
			sb.append(" AND last_updated_on LIKE '%" + dto.getLastUpdtOn()
					+ "%' ");
		}

		System.out.println(sb.toString());
		return (List<VyLookupQualificationDO>) QueryManager.executeListQuery(
				dto, sb.toString());
	}

	public static VyLookupQualificationDO insert(VyLookupQualificationDO dto)
			throws Exception {

		dto = (VyLookupQualificationDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyLookupQualificationDO update(VyLookupQualificationDO dto)
			throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static VyLookupQualificationDO delete(VyLookupQualificationDO dto) throws Exception {
		int i = QueryManager.executeUpdate(dto, DELETE);
		if (i > 0)
			return dto;
		else
			return null;
	}
}
